﻿using System;
using System.IO;
using System.Linq;
using System.Reflection;
using Codeflows.Configuration;

namespace CodeflowsHost.Configuration
{
    public class HostConfigurator
    {
        public static void ApplyHostConfigurations()
        {            
            var configurators = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll")
                .Select(Assembly.LoadFile)
                .SelectMany(a => a.GetTypes())
                .Where(t => t.IsClass)
                .Where(t => typeof(IConfigureCodeflowHosts).IsAssignableFrom(t))
                .Select(t => (IConfigureCodeflowHosts)Activator.CreateInstance(t));

            foreach (var configurator in configurators)
            {
                configurator.Configure();
            }
        } 
    }
}